package com.novelastudios.math
{
	/**
	 * @author Rockfish Interactive ©2010
	 */
	public class InterestUtil
	{
		
		//////////////////////////////////////////////////////////////////////////////////////////////////
		//										PUBLIC METHODS
		//////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * This is the most common formula for Compound Interest.
		 *  
		 * @param principal	Initial investment / principal investment
		 * @param rate		Interest rate per period (year)
		 * @param years		How many periods (years)
		 * @param contribution	Contribution amount per term
		 * @param timesPerYear 	How many times per period (the term) is the interest compounded (default: once = 1)
		 * 
		 * @return  The future value
		 * 
		 * @cite Algorithm and furthure description at http://www.rgarden.glandrake.com/java/InterestCalc.htm
		 */				
		public static function getCompoundFutureValue(principal:Number,rate:Number,years:Number,contribution:Number=0,timesPerYear:Number=1):Number
		{
			var totalTerms:Number = years*timesPerYear;
			return principal * Math.pow( 1 + rate,totalTerms) + contribution *( ( Math.pow(1+rate,totalTerms+1) - 1 - rate) / rate) ;
		}
		
		
	}
}